package com.yupi.generator;

import com.yupi.model.MainTemplateConfig;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;


/**
 *汇总静态和动态生成
 */
public class MainGenerator {


    public static void doGenerate(Object model) throws TemplateException, IOException {
        String inputRootPath =  "E:\\Code\\yuzi-generator\\yuzi-generator-demo-projects\\acm-template-pro";
        String outputRootPath =  "E:\\Code\\yuzi-generator";

        String inputPath;
        String outputPath;


        //动态模板生成器，生成MainTemplate.java
        inputPath = new File(inputRootPath,"src/main/resources/templates/MainTemplate.java.ftl").getAbsolutePath();
        outputPath = new File(outputRootPath,"src/main/yupi/acm/MainTemplate.java").getAbsolutePath();
        DynamicGenerator.doGenerate(inputPath,outputPath,model);

        //静态模板生成器，生成.gitignore
        inputPath = new File(inputRootPath,".gitignore").getAbsolutePath();
        outputPath = new File(outputRootPath,".gitignore").getAbsolutePath();
        StaticGenerator.copyFilesByRecursive(inputPath,outputPath);

        //静态模板生成器，生成Readme文件
        inputPath = new File(inputRootPath,"README.md").getAbsolutePath();
        outputPath = new File(outputRootPath,"README.md").getAbsolutePath();
       StaticGenerator.copyFilesByRecursive(inputPath,outputPath);

    }


    public static void main(String[] args) throws TemplateException, IOException {
        MainTemplateConfig mainTemplateConfig = new MainTemplateConfig();
        // 这次使用循环
        mainTemplateConfig.setLoop(true);
        mainTemplateConfig.setAuthor("cjj");
        mainTemplateConfig.setOutputText("求和结果：");
        doGenerate(mainTemplateConfig);
    }



}

